package com.sqly.doc.user;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
//import com.hyphenate.EMCallBack;
//import com.hyphenate.chat.EMClient;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.RequestParams;
import com.sqly.doc.MainActivity;
import com.sqly.doc.R;
import com.sqly.doc.base.MyBaseActivity;
import com.sqly.doc.menu.camera.CameraChoose;
import com.sqly.doc.pojo.BleEquip;
import com.sqly.doc.pojo.JuMin;
import com.sqly.doc.pojo.RetMsg;
import com.sqly.doc.pojo.ServicePackage;
import com.sqly.doc.pojo.SignUp;
import com.sqly.doc.pojo.Team;
import com.sqly.doc.pojo.TeamMember;
import com.sqly.doc.util.HttpUrl;
import com.sqly.doc.util.MyToastUtil;
import com.sqly.doc.util.NetWorkUtils;
import com.sqly.doc.util.SharedPreferencesUtils;
import com.sqly.doc.util.UplodeManager;
import com.sqly.doc.util.UserClient;
import com.sqly.doc.view.StringUtils;
import com.zyao89.view.zloading.ZLoadingDialog;
import com.zyao89.view.zloading.Z_TYPE;

import org.litepal.crud.DataSupport;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.List;

import cz.msebera.android.httpclient.Header;

/**
 * 用户登录
 *
 * @author 张兴宝
 */
public class user_login extends MyBaseActivity {
    List<ServicePackage> servicelist;//服务包列表数据
    Button login;//登录按钮
    EditText username, password;
    CheckBox jzmm;
    Context con = user_login.this;
    ZLoadingDialog dialog;
    List<JuMin> jmlist;//居民
    int jmcount = 0;//居民
    List<SignUp> signlist;
    int signcount=0;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        initUI();
        initData();
        initListener();

    }

    @Override
    protected void initUI() {
        // TODO Auto-generated method stub
        setContentView(R.layout.user_login);
        login = (Button) findViewById(R.id.login);
        username = (EditText) findViewById(R.id.username);
        password = (EditText) findViewById(R.id.password);
        username.setText(SharedPreferencesUtils.getParam(con, "username", "").toString());
        password.setText(SharedPreferencesUtils.getParam(con, "password", "").toString());
        jzmm = (CheckBox) findViewById(R.id.jzmm);
        username.setText(SharedPreferencesUtils.getParam(con, "username", "").toString());
        password.setText(SharedPreferencesUtils.getParam(con, "password", "").toString());
        dialog = new ZLoadingDialog(con);
        dialog.setLoadingBuilder(Z_TYPE.DOUBLE_CIRCLE)//设置类型
                .setLoadingColor(Color.parseColor("#1C86EE"))//颜色
                .setHintText("Loading...")
                .setHintTextSize(16) // 设置字体大小 dp
                .setHintTextColor(Color.parseColor("#1C86EE"));  // 设置字体颜色
    }

    @Override
    protected void initData() {
        // TODO Auto-generated method stub

    }

    @Override
    protected void initListener() {
        // TODO Auto-generated method stub
        login.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if( null ==username.getText().toString() || "".equals( username.getText().toString())){
                    MyToastUtil.ShowToast(con, "账户名称不能为空");
                }else if(null ==password.getText().toString() || "".equals( password.getText().toString())){
                    MyToastUtil.ShowToast(con, "密码不能为空");
                }else if (NetWorkUtils.isNetworkConnected(con)) {
                    //网络可以使用
                    signcount=0;
                    jmcount=0;
                    RequestParams ps = new RequestParams();
                    ps.add("username", username.getText().toString());
                    ps.add("password", password.getText().toString());
                    ps.add("type", "2");
                    UserClient.get(HttpUrl.User_Login, ps, new AsyncHttpResponseHandler() {
                        @Override
                        public void onStart() {
                            super.onStart();
                            dialog.show();
                        }

                        @Override
                        public void onFailure(int statusCode, Header[] headers, byte[] errorResponse, Throwable e) {

                            dialog.dismiss();
//                            if (SharedPreferencesUtils.getParam(con, "username", "").toString().equals(username.getText().toString())
//                                    && SharedPreferencesUtils.getParam(con, "password", "").toString().equals(password.getText().toString())) {
//                                MyToastUtil.ShowToast(con, "登录成功");
//                                startActivity(new Intent(con, MainActivity.class));
//                                finish();
//
//                            } else {
                                MyToastUtil.ShowToast(con, "联网失败");
//                            }
                        }

                        @Override
                        public void onSuccess(int statusCode, Header[] headers, byte[] response) {
                            String content = new String(response);
                            Log.i("登录成功",content);
                            RetMsg ret = JSON.parseObject(content, RetMsg.class);
                            JSONObject j = JSON.parseObject(ret.getRd());
                            if (ret.getCode().equals("200")) {
                                MyToastUtil.ShowToast(con, "登录成功");
                                if (jzmm.isChecked()) {
                                    SharedPreferencesUtils.setParam(con, "username", username.getText().toString());
                                    SharedPreferencesUtils.setParam(con, "password", password.getText().toString());
                                } else {
                                    SharedPreferencesUtils.setParam(con, "username", "");
                                    SharedPreferencesUtils.setParam(con, "password", "");
                                }
                                SharedPreferencesUtils.setParam(con, "uid", username.getText().toString());
                                SharedPreferencesUtils.setParam(con, "token", j.getString("_token"));
                                SharedPreferencesUtils.setParam(con, "ruid", j.getString("jkdah"));
                                SharedPreferencesUtils.setParam(con, "teamid", StringUtils.isEmpty(j.getString("teamid"))?"":j.getString("teamid"));
                                SharedPreferencesUtils.setParam(con, "uname", StringUtils.isEmpty(j.getString("name"))?"":j.getString("name"));
                                SharedPreferencesUtils.setParam(con, "phone",StringUtils.isEmpty(j.getString("phone"))?"":j.getString("phone"));
                                SharedPreferencesUtils.setParam(con, "isxzgly",StringUtils.isEmpty(j.getString("isxzgly"))?"":j.getString("isxzgly"));
                                SharedPreferencesUtils.setParam(con, "xzgly",StringUtils.isEmpty(j.getString("xzgly"))?"0":j.getString("xzgly"));
                                if(null == SharedPreferencesUtils.getParam(con, "xyjval", "") || "".equals(SharedPreferencesUtils.getParam(con, "xyjval", ""))){
                                    SharedPreferencesUtils.setParam(con, "xyjval", "");
                                }
                                if(null == SharedPreferencesUtils.getParam(con, "xtyval", "") || "".equals(SharedPreferencesUtils.getParam(con, "xtyval", ""))){
                                    SharedPreferencesUtils.setParam(con, "xtyval", "");
                                }
                                getBleEquip();
                                //getServicePackage();
                                isupdate();
                            }else{
                                MyToastUtil.ShowToast(con, ret.getInfo());
                                dialog.dismiss();
                            }
                        }
                    });
                } else {//网络不能使用，也能进入，但是首次不行
//                    if (SharedPreferencesUtils.getParam(con, "username", "").toString().equals(username.getText().toString())
//                            && SharedPreferencesUtils.getParam(con, "password", "").toString().equals(password.getText().toString())) {
//                        MyToastUtil.ShowToast(con, "登录成功");
//                        startActivity(new Intent(con, MainActivity.class));
//                        finish();
//
//                    } else {
//                        MyToastUtil.ShowToast(con, "登录失败");
//                    }
                    MyToastUtil.ShowToast(con, "登录失败");
                }
            }
        });
    }

    //获取藍牙設備信息
    public void getBleEquip() {
        RequestParams ps = new RequestParams();
        ps.add("token", SharedPreferencesUtils.getParam(con, "token", "").toString());
        ps.add("type", "2");
        UserClient.get(HttpUrl.GetAllBleEquip, ps, new AsyncHttpResponseHandler() {
            @Override
            public void onFailure(int statusCode, Header[] headers, byte[] errorResponse, Throwable e) {

                //MyToastUtil.ShowToast(con, "蓝牙设备获取失败");
            }
            @Override
            public void onSuccess(int statusCode, Header[] headers, byte[] response) {
                String content = new String(response);
                Log.i("蓝牙设备数据", content);
                RetMsg ret = JSON.parseObject(content, RetMsg.class);
                if(null != ret.getRd()) {
                    List<BleEquip> equiplist = JSON.parseArray(ret.getRd(), BleEquip.class);
                    for (BleEquip bleEquip : equiplist){
                        if(null != bleEquip.getCategory() && "1".equals(bleEquip.getCategory())){
                            SharedPreferencesUtils.setParam(con, "xtyval", bleEquip.getMac());
                        }
                        if(null != bleEquip.getCategory() && "2".equals(bleEquip.getCategory())){
                            SharedPreferencesUtils.setParam(con, "xyjval", bleEquip.getMac());
                        }
                    }
                }
            }
        });
    }

    //获取服务包信息
    public void getServicePackage() {
        RequestParams ps = new RequestParams();
        ps.add("token", SharedPreferencesUtils.getParam(con, "token", "").toString());
        ps.add("type", "2");
        UserClient.get(HttpUrl.GetAllServicePackage, ps, new AsyncHttpResponseHandler() {
            @Override
            public void onFailure(int statusCode, Header[] headers, byte[] errorResponse, Throwable e) {

                MyToastUtil.ShowToast(con, "服务包获取失败");
            }

            @Override
            public void onSuccess(int statusCode, Header[] headers, byte[] response) {
                String content = new String(response);
                Log.i("服務包數據", content);
                RetMsg ret = JSON.parseObject(content, RetMsg.class);
                servicelist = JSON.parseArray(ret.getRd(), ServicePackage.class);
                if(null != ret.getRd()) {
                    JSONArray js = JSON.parseArray(ret.getRd());
                    for (int i = 0; i < js.size(); i++) {
                        JSONObject j = js.getJSONObject(i);
                        servicelist.get(i).setSid(j.getString("id"));
                    }
                }
                List<ServicePackage> dblist = DataSupport.findAll(ServicePackage.class);
                if (dblist.size() > 0) {
                    //本地数据没有
                    for (int i = 0; i < servicelist.size(); i++) {
                        List<ServicePackage> jlist = DataSupport.where("name = ?", servicelist.get(i).getName()).find(ServicePackage.class);
                        if (jlist.size() > 0) {
                            Log.i("服务包数据", "删除后插入的数据");
                            jlist.get(0).delete();
                            servicelist.get(i).save();
                        } else {
                            Log.i("服务包数据1111", "直接插入的数据");
                            servicelist.get(i).save();
                        }

                    }
                } else {
                    Log.i("服务包数据", "直接插入的数据");
                    if(null != servicelist) {
                        for (ServicePackage j : servicelist) {
                            j.save();
                        }
                    }
                    Log.i("服务包数据-----", DataSupport.findAll(ServicePackage.class).size() + "");
                }
                getTeam();
            }
        });
    }

    /***
     * 获取团队信息
     */
    public void getTeam() {
        RequestParams ps = new RequestParams();
        ps.add("token", SharedPreferencesUtils.getParam(con, "token", "").toString());
        ps.add("type", "2");
        UserClient.get(HttpUrl.GetAllTeam, ps, new AsyncHttpResponseHandler() {
            @Override
            public void onStart() {
                super.onStart();
                dialog.show();
            }

            @Override
            public void onFailure(int statusCode, Header[] headers, byte[] errorResponse, Throwable e) {

                dialog.dismiss();
                MyToastUtil.ShowToast(con, "请求失败");
            }

            @Override
            public void onSuccess(int statusCode, Header[] headers, byte[] response) {
                String content = new String(response);
                dialog.dismiss();
                RetMsg ret = JSON.parseObject(content, RetMsg.class);
                if (ret.getCode().equals("200")) {
                    List<Team> list = JSON.parseArray(ret.getRd(), Team.class);
                    JSONArray js = JSON.parseArray(ret.getRd());
                    for (int i = 0; i < js.size(); i++) {
                        JSONObject j = js.getJSONObject(i);
                        list.get(i).setTid(j.getString("id"));
                    }
                    List<Team> dblist = DataSupport.findAll(Team.class);
                    if (dblist.size() > 0) {//本地数据没有
                        for (int i = 0; i < list.size(); i++) {
                            List<Team> jlist = DataSupport.where("name = ?", list.get(i).getName()).find(Team.class);
                            if (jlist.size() > 0) {
                                Log.i("团队数据", "删除后插入的数据");
                                jlist.get(0).delete();
                                list.get(i).save();
                            } else {
                                Log.i("团队数据1111", "直接插入的数据");
                                list.get(i).save();
                            }

                        }
                    } else {
                        Log.i("团队数据", "直接插入的数据");
                        for (Team j : list) {
                            j.save();
                        }
                        Log.i("团队数据-----", DataSupport.findAll(Team.class).size() + "");
                    }
                    getTeamMember();
                } else {
                    MyToastUtil.ShowToast(con, "团队信息获取错误");
                }

            }
        });
    }

    public void getTeamMember() {
        RequestParams ps = new RequestParams();
        ps.add("token", SharedPreferencesUtils.getParam(con, "token", "").toString());
        ps.add("type", "2");
        UserClient.get(HttpUrl.GetAllTeamMember, ps, new AsyncHttpResponseHandler() {
            @Override
            public void onStart() {
                super.onStart();
                dialog.show();
            }

            @Override
            public void onFailure(int statusCode, Header[] headers, byte[] errorResponse, Throwable e) {

                dialog.dismiss();
                MyToastUtil.ShowToast(con, "请求失败");
            }

            @Override
            public void onSuccess(int statusCode, Header[] headers, byte[] response) {
                String content = new String(response);
                dialog.dismiss();
                RetMsg ret = JSON.parseObject(content, RetMsg.class);
                if (ret.getCode().equals("200")) {

                    List<TeamMember> list = JSON.parseArray(ret.getRd(), TeamMember.class);
                    JSONArray js = JSON.parseArray(ret.getRd());
                    for (int i = 0; i < js.size(); i++) {
                        JSONObject j = js.getJSONObject(i);
                        list.get(i).setTmid(j.getString("id"));
                    }
                    List<TeamMember> dblist = DataSupport.findAll(TeamMember.class);
                    if (dblist.size() > 0) {//本地数据没有
                        for (int i = 0; i < list.size(); i++) {
                            List<TeamMember> jlist = DataSupport.where("member_code = ?", list.get(i).getMember_code()).find(TeamMember.class);
                            if (jlist.size() > 0) {
                                Log.i("团队成员数据", "删除后插入的数据");
                                jlist.get(0).delete();
                                list.get(i).save();
                            } else {
                                Log.i("团队成员数据1111", "直接插入的数据");
                                list.get(i).save();
                            }

                        }
                    } else {
                        Log.i("团队成员数据", "直接插入的数据");
                        for (TeamMember j : list) {
                            j.save();
                        }
                        Log.i("团队成员数据-----", DataSupport.findAll(TeamMember.class).size() + "");
                    }
                    uploadJumin();
                } else {
                    MyToastUtil.ShowToast(con, "团队成员获取错误");
                }
            }
        });
    }

    //上传居民信息
    public void uploadJumin() {
        jmlist = DataSupport.where("isupdate=2").find(JuMin.class);
        if (jmlist.size() > 0)
            doJumin(jmlist.get(jmcount));
        else {
           uploadSignUp();
        }
    }
    //上传签约信息
    public void uploadSignUp() {
        signlist = DataSupport.where("isupdate=2").find(SignUp.class);
        if (signlist.size() > 0)
            doSignup(signlist.get(signcount));
        else {
           isupdate();
        }
    }

    //签约信息通信
    public void doSignup(final SignUp obj){
        RequestParams ps = new RequestParams();
        ps.add("type", "2");
        ps.add("token", SharedPreferencesUtils.getParam(con, "token", "").toString());
        ps.add("entity.party_a_contractor_id", obj.getContract_age());
        ps.add("entity.party_a_contractor_id", obj.getParty_a_contractor_id());
        ps.add("entity.party_a_contractor_name", obj.getParty_a_contractor_name());
        ps.add("entity.party_a_team_id", obj.getParty_a_team_id());
        ps.add("entity.party_a_team_name", obj.getParty_a_team_name());
        ps.add("entity.party_a_tel", obj.getParty_a_tel());
        ps.add("entity.party_b_tel", obj.getParty_b_tel());
        ps.add("entity.party_b_addr", obj.getParty_b_addr());
        ps.add("entity.party_b_id", obj.getParty_b_id());
        ps.add("entity.party_b_name", obj.getParty_b_name());
        ps.add("entity.tbtime", obj.getTbtime());
        ps.add("service_pack_id", obj.getService_pack_id());
        if(!StringUtils.isEmpty(obj.getQm())) {
            try {
                ps.put("img", new File(Environment.getExternalStorageDirectory() + "/" + obj.getQm() + ".jpg"));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }
        UserClient.get(HttpUrl.SignAdd, ps, new AsyncHttpResponseHandler() {
            @Override
            public void onStart() {
                super.onStart();
                dialog.show();
            }

            @Override
            public void onSuccess(int statusCode, Header[] headers, byte[] response) {
                String content = new String(response);
                dialog.dismiss();
                MyToastUtil.ShowToast(con, content);
              obj.setIsupdate("1");
                obj.update(obj.getId());
                signcount = signcount + 1;
                if (signcount < signlist.size()) {
                    doSignup(signlist.get(signcount));
                } else {
                    isupdate();
                }
            }

            @Override
            public void onFailure(int statusCode, Header[] headers, byte[] errorResponse, Throwable e) {

                dialog.dismiss();
            }
        });
    }

    //居民信息通信
    public void doJumin(final JuMin obj) {
        String jmurl = "";
        RequestParams ps = new RequestParams();
                        /*ps.add("entity.SCJDRQ", obj.getSCJDRQ());*/
        ps.add("entity.XINGMING", obj.getXINGMING());
        ps.add("entity.SFZH", obj.getSFZH());
        ps.add("entity.CSRQ", obj.getCSRQ());
        ps.add("entity.XINGBIE", obj.getXINGBIE());
        ps.add("entity.GZDW", obj.getGZDW());
        ps.add("entity.LXDH", obj.getLXDH());
        ps.add("entity.LXRXM", obj.getLXRXM());
        ps.add("entity.CZLX", obj.getCZLX());
        ps.add("entity.HJDZ", obj.getHJDZ());
        ps.add("entity.MINZU", obj.getMINZU());
        ps.add("entity.XUEXING", obj.getXUEXING());
        ps.add("entity.XUEXINGRH", obj.getXUEXINGRH());
        ps.add("entity.WHCD", obj.getWHCD());
        ps.add("entity.ZHIYE", obj.getZHIYE());
        ps.add("entity.HYQK", obj.getHYQK());
        ps.add("entity.YLFYZFFS", obj.getYLFYZFFS());
        ps.add("entity.YLFYZFFSQT", obj.getYLFYZFFSQT());
        ps.add("entity.YBKH", obj.getYBKH());
        ps.add("entity.ZGKH", obj.getZGKH());
        ps.add("entity.PKJZKH", obj.getPKJZKH());
        ps.add("entity.YWGMS", obj.getYWGMS());
        ps.add("entity.YWGMSQT", obj.getYWGMSQT());
        ps.add("entity.BLS", obj.getBLS());
        ps.add("entity.JWSJB", obj.getJWSJB());
        ps.add("entity.JWSJBQT", obj.getJWSJBQT());
        ps.add("entity.GXYQZRQ", obj.getGXYQZRQ());
        ps.add("entity.TNBQZRQ", obj.getTNBQZRQ());
        ps.add("entity.GXYQZRQ", obj.getGXYQZRQ());
        ps.add("entity.MXZSXFJBQZRQ", obj.getMXZSXFJBQZRQ());
        ps.add("entity.EXZLQZRQ", obj.getEXZLQZRQ());
        ps.add("entity.NCZQZRQ", obj.getNCZQZRQ());
        ps.add("entity.JSBQZRQ", obj.getJSBQZRQ());
        ps.add("entity.JHBQZRQ", obj.getJHBQZRQ());
        ps.add("entity.GYQZRQ", obj.getGYQZRQ());
        ps.add("entity.CRBQZRQ", obj.getCRBQZRQ());
        ps.add("entity.ZYBQZRQ", obj.getZYBQZRQ());
        ps.add("entity.JWSSS", obj.getJWSSS());
        ps.add("entity.JWSSSMC1", obj.getJWSSSMC1());
        ps.add("entity.JWSSSRQ1", obj.getJWSSSRQ1());
        ps.add("entity.JWSSSMC2", obj.getJWSSSMC2());
        ps.add("entity.JWSSSRQ2", obj.getJWSSSRQ2());
        ps.add("entity.JWSWSMC1", obj.getJWSWSMC1());
        ps.add("entity.JWSWSRQ1", obj.getJWSWSRQ1());
        ps.add("entity.JWSWSMC2", obj.getJWSWSMC2());
        ps.add("entity.JWSWSRQ2", obj.getJWSWSRQ2());
        ps.add("entity.JWSSXYY1", obj.getJWSSXYY1());
        ps.add("entity.JWSSXRQ1", obj.getJWSSXRQ1());
        ps.add("entity.JWSSXYY2", obj.getJWSSXYY2());
        ps.add("entity.JWSSXRQ2", obj.getJWSSXRQ2());
        ps.add("entity.JZSFQ", obj.getJZSFQ());
        ps.add("entity.JZSMQ", obj.getJZSMQ());
        ps.add("entity.JZSXDJM", obj.getJZSXDJM());
        ps.add("entity.JZSZN", obj.getJZSZN());
        ps.add("entity.YCBS", obj.getYCBS());
        ps.add("entity.YCBSMC", obj.getYCBSMC());
        ps.add("entity.CJQK", obj.getCJQK());
        if (!StringUtils.isEmpty(obj.getCARDNUM())) {
            jmurl = HttpUrl.EditGrjbxx;
            ps.add("entity.CARDNUM", obj.getCARDNUM());
        } else {
            jmurl = HttpUrl.SaveGrjbxx;
        }

        if(!StringUtils.isEmpty(obj.getQm())) {
            try {
                ps.put("img", new File(Environment.getExternalStorageDirectory() + "/" + obj.getQm() + ".jpg"));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }
        ps.add("token", SharedPreferencesUtils.getParam(con, "token", "").toString());
        ps.add("type", "2");
        UserClient.get(jmurl, ps, new AsyncHttpResponseHandler() {
            @Override
            public void onSuccess(int statusCode, Header[] headers, byte[] response) {
                String content = new String(response);
                Log.i("个人基本信息保存", content);
                MyToastUtil.ShowToast(con, "保存成功");
                obj.setIsupdate("1");
                obj.update(obj.getId());
                jmcount = jmcount + 1;
                if (jmcount < jmlist.size()) {
                    doJumin(jmlist.get(jmcount));
                } else {
                    uploadSignUp();
                }

            }

            @Override
            public void onFailure(int statusCode, Header[] headers, byte[] errorResponse, Throwable e) {

                MyToastUtil.ShowToast(con, "保存失败");
            }
        });
    }

//判断是否需需要进行更新
    public void isupdate(){

        RequestParams ps=new RequestParams();
        ps.add("token",SharedPreferencesUtils.getParam(con,"token","").toString());
        ps.add("type","2");
        ps.add("version","1.5.3");
        UserClient.get(HttpUrl.IsUpdate,ps,new AsyncHttpResponseHandler(){
            @Override
            public void onSuccess(int statusCode, Header[] headers, byte[] response) {
                String content = new String(response);
                RetMsg ret=JSON.parseObject(content,RetMsg.class);
                if(ret.getCode().equals("200")){
                    JSONObject j = JSON.parseObject(ret.getOtherParams());
                    if(null != j){
                        JSONObject setarr = JSON.parseObject(j.getString("setarr"));
                        if(null != setarr){
                            SharedPreferencesUtils.setParam(con, "ysqm",StringUtils.isEmpty(setarr.getString("ysqm"))?"0":setarr.getString("ysqm"));
                            SharedPreferencesUtils.setParam(con, "jmqm",StringUtils.isEmpty(setarr.getString("jmqm"))?"0":setarr.getString("jmqm"));
                            SharedPreferencesUtils.setParam(con, "xcpz",StringUtils.isEmpty(setarr.getString("xcpz"))?"0":setarr.getString("xcpz"));
                            SharedPreferencesUtils.setParam(con, "gxycj",StringUtils.isEmpty(setarr.getString("gxycj"))?"0":setarr.getString("gxycj"));
                            SharedPreferencesUtils.setParam(con, "tnbcj",StringUtils.isEmpty(setarr.getString("tnbcj"))?"0":setarr.getString("tnbcj"));
                        }
                    }

                    UplodeManager mUpdateManager = new UplodeManager(con,ret.getRd());
                    mUpdateManager.checkUpdateInfo();
                }else{
                    JSONObject j = JSON.parseObject(ret.getOtherParams());
                    if(null != j){
                        JSONObject setarr = JSON.parseObject(j.getString("setarr"));
                        if(null != setarr){
                            SharedPreferencesUtils.setParam(con, "ysqm",StringUtils.isEmpty(setarr.getString("ysqm"))?"0":setarr.getString("ysqm"));
                            SharedPreferencesUtils.setParam(con, "jmqm",StringUtils.isEmpty(setarr.getString("jmqm"))?"0":setarr.getString("jmqm"));
                            SharedPreferencesUtils.setParam(con, "xcpz",StringUtils.isEmpty(setarr.getString("xcpz"))?"0":setarr.getString("xcpz"));
                            SharedPreferencesUtils.setParam(con, "gxycj",StringUtils.isEmpty(setarr.getString("gxycj"))?"0":setarr.getString("gxycj"));
                            SharedPreferencesUtils.setParam(con, "tnbcj",StringUtils.isEmpty(setarr.getString("tnbcj"))?"0":setarr.getString("tnbcj"));
                        }
                    }
                    startActivity(new Intent(con, MainActivity.class));
                    finish();
                }
            }

            @Override
            public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
            }
        });
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (dialog != null) {
            dialog.dismiss();
        }
    }
}
